<?php

namespace App\Models\admin;

use Illuminate\Database\Eloquent\Model;

class Category extends Model
{
    //
    protected $table='article_category';


    /**
     * 生成上级分类下拉选项框
     * @param $pid
     * @return string
     */
    public function getCateSelect($pid)
    {
        $html = '<select class="form-control" name="cate_id">';
        $html .= '<option value="">--请选择--</option>';
        foreach($this->orderby('pid','ASC')->get() as $key => $value){
            if($pid == $value->id){
                $html .= '<option value="'.$value->id.'" selected>'.$value->name.'</option>';
            }else{
                $html .= '<option value="'.$value->id.'">'.$value->name.'</option>';
            }
        }
        $html .= '</select>';
        return $html;
    }
}
